package game.web.controller;

import game.web.base.Constants;
import game.web.dao.dto.ChargeDTO;
import game.web.entity.ChargeEntityManager;
import game.web.struts.ChargeForm;
import projectx.core.base.ProjectXSystemException;
import projectx.core.base.ProjectXUserException;
import projectx.transaction.TransactionHandler;
import projectx.util.ClassUtil;
import projectx.util.TicketUtil;
import projectx.web.base.ConstantsProjectX;
import projectx.web.base.ProjectXDbTrxController;
import projectx.web.base.ProjectXForm;
import projectx.web.base.UserContext;

public class ChargeControllor extends ProjectXDbTrxController {

	protected ChargeControllor(UserContext uc, ProjectXForm form) {
		super(uc, form);
	}

	@Override
	public Object execute() throws ProjectXUserException,
			ProjectXSystemException {

		debugBegin();

		UserContext uc = getUc();

		ChargeForm form = (ChargeForm) getForm();
		
		ChargeDTO dto = new ChargeDTO();
		
		ClassUtil.copyData(form, dto);

		String ip = (String) uc.get(ConstantsProjectX.CURRENT_IP);
		String userid = (String) uc.get(ConstantsProjectX.USER_ID);
		
		dto.setId(TicketUtil.getTicket(Constants.CHARGE_INDEX));
		dto.setUserid(userid);
		dto.setCreatetime(getCurrentTimeString());
		dto.setUpdatetime(getCurrentTimeString());
		dto.setCreateip(ip);
		dto.setUpdateip(ip);
		
		ChargeEntityManager.insert(dto);

		uc.put(Constants.CHARGE_ACION, dto);

		debugEnd();
		return null;
	}

	public static Object execute(UserContext uc, ProjectXForm form)
			throws ProjectXUserException, ProjectXSystemException {
		return TransactionHandler.call(new ChargeControllor(uc, form));
	}
}
